#include "StdAfx.h"
#define _AFXDLL
#include "Browser.h"

#include <io.h>

void
GetFilesInDirectory(const string& suchPfad, const string& wildCard,
                    unsigned attribut, BOOL fNormal,
                    list< string >& stringList)
{
  struct _finddata_t find;
  
  if(suchPfad.empty())
    return;

  string pathAndWildCard, pathAndFileName, fullPath;
  if ((suchPfad.find_last_of("/") != suchPfad.size()-1) && (suchPfad.find_last_of("\\") != suchPfad.size()-1))
    fullPath = suchPfad + "/";
  else
    fullPath = suchPfad;
  pathAndWildCard = fullPath + wildCard;

  
  stringList.clear();
  
  long hSearch = _findfirst(pathAndWildCard.c_str(), &find);
  if ( hSearch != -1)
  {
    do
    {
      if( (find.attrib & attribut) || (attribut == 0) || (fNormal && (find.attrib==0)))
      {
        if( find.name[0] != '.' )
        {
          pathAndFileName = fullPath + find.name;
          stringList.push_back(pathAndFileName);
        }
      }
    }
    while( _findnext(hSearch, &find) == 0 );
    _findclose(hSearch);
  }
}

bool
AddFileExtension(const string& fileAndPath, const string& extension, string& extendedFileAndPath, char ch)
{
  int pos = fileAndPath.find_last_of(ch);
  if (pos == basic_string<char>::npos)
    return false;

  string stringEnd;
  stringEnd = fileAndPath;
  stringEnd.erase(0, pos);
  extendedFileAndPath = fileAndPath;
  extendedFileAndPath.erase(pos-1, basic_string<char>::npos);
  extendedFileAndPath = extendedFileAndPath + extension + stringEnd;

  return true;
}


